var str = location.href;
// alert(str);
// 获取当页面的Id
var arr = str.split("=");
var p = 1;
if(arr[1])
{
	p = parseInt(arr[1]);
}
$(function(){
	$.ajax({
		type:"post",
		url:"/v1/website/product",
		dataType:"json",
		data:{p:p},
		success:function (data) {
			console.log(data);
			if(data.code == 200) {
				// 产品列表
				var list = data.data;
				var rateLsit = list.product;
				var htmlStr = '';
				// var productID = 
				// 图片
				var banner = list.cover_img;
				var bannerPic = '';
				// 分页
				var pageTotal = list.page;//总页数
				var curPage = list.p;//当前页
				// alert(totalP);
				// alert(currentP);


				
				
				// 产品列表数据
				// alert(rateLsit.length)
				// 判断是否有图片
				for(var i=0; i<rateLsit.length;i++){
					var kefuImg1 = rateLsit[i].custom1_img;
					var kefuImg2 = rateLsit[i].custom2_img;
					var kefuImg3 = rateLsit[i].custom3_img;
					if(kefuImg1 == ""){
						kefuImg1 = "../../img/websiteImg/MRserver.png"
					}if(kefuImg2 == ""){
						kefuImg2 = "../../img/websiteImg/MRserver.png"
					}if(kefuImg3 == ""){
						kefuImg3 = "../../img/websiteImg/MRserver.png"
					}
					// 判断有无抵押
					var YNDY = rateLsit[i].is_mortgage;
					if(rateLsit[i].is_mortgage == 0){
						YNDY = "无抵押"
					}else{
						YNDY = "有抵押"
					}
					
					htmlStr +=  
						'<div class="productItem" onclick="window.open(\'productDetail.html?id=' + rateLsit[i].id +'\')">'
					+'<span class="rightLogo"><img src="../../img/websiteImg/bankRightLogo.png"/></span>'
					+'<div class="productItemTop">'
					+'<div class="productItemTop1">'    		
					+'<span id="productItemTop1Lilv">'+ rateLsit[i].rate +'%</span>'
					+'<span id="roductItemTop1Title">'+ rateLsit[i].rate_label +'</span>'
					+'</div>'    		
					+'<div class="productItemTop2">'    		
					+'<div class="productItemTop2top">'    			
					+'<span id="" class="productItemTop2topPic"><img src="../../img/websiteImg/moneyProduct.png"/></span>'  				
					+'<span>可贷金额：'+ rateLsit[i].money+'</span>'
					+'</div>'
					+'<div class="productItemTop2mid">'    			
					+'<span id="" class="productItemTop2topPic"><img src="../../img/websiteImg/dayProduct.png"/></span>'    				
					+'<span>还款期限：'+ rateLsit[i].time_limit+'年</span>'
					+'</div>'
					+'<div class="productItemTop2bottom">'    			
					+'<span id="" class="productItemTop2topPic"><img src="../../img/websiteImg/diyaProduct.png"/></span>'    				
					+'<span>有无抵押：' + YNDY + '<span>(' + rateLsit[i].desc_mortgage + ')</span></span>'
					+'</div>'    			
					+'</div>'    		
					+'<div class="productItemTop3">'    		
					+'<img src=" ' + rateLsit[i].company_logo +'" alt=" '+ rateLsit[i].company_logo_alt +' " width="190" height="110"/>'    			
					+ '</div>'    		
					+ '</div>'    	
					+ '<div class="productItemBottom">'    	
					+'<div class="productItemBottom1">'    		
					+ '<img src=" ' + rateLsit[i].product_logo +'" alt=" '+ rateLsit[i].product_logo_alt +' "/>'    			
					+ '</div>'    		
					+ '<div class="productItemBottom2">'  		
					+ '<p class="productItemBottom2Title">' + rateLsit[i].title + '</p>'
					+ '<div class="productItemBottom2Content">' + rateLsit[i].content  +'</div>'
					+ '</div>'    		
					+ '<div class="productItemBottom3">'    		
					+ '<p>产品客服</p>'    			
					+ '<span><img src=" '+ kefuImg1 +'" alt=" '+ rateLsit[i].custom1_alt +' " width="44" height="44"/></span>'    			
					+ '<span><img src=" '+ kefuImg2 +'" alt=" '+ rateLsit[i].custom2_alt +' " width="44" height="44"/></span>'    			
					+ '<span><img src=" '+ kefuImg3 +'" alt=" '+ rateLsit[i].custom3_alt +' " width="44" height="44"/></span>'    			
					+ '<br />'   			
					+ '<div class="askNow"><a href="#" target="_blank">立即咨询</a></div>'   			
					+ '</div>'   	    
					+ '</div>'   	
					+ '</div>'   
				}
				 $('.productItem').html(htmlStr);
				$("#pagination2").pagination({
					currentPage: p,
					totalPage: parseInt(list.page),
					isShow: false,
					count: 10,
					prevPageText: "< 上一页",
					nextPageText: "下一页 >",
					callback: function(current) {
						$("#current2").text(current)
					}
				});
				 $('.bannerProduct img').attr('src', banner);
			}
		},
// 		error: function (XMLHttpRequest) {
// 			if( XMLHttpRequest.status == 400)
// 			{
// 				location.href = "404.html";
// 			}
// 			else
// 			{
// 				location.href = "505.html";
// 			}
// 		}
		
	})
})

